import {observable} from "mobx";
import service from 'libs/request';
import {simpleIndex} from "../../../api/work/GenerateApi";
import {Popconfirm} from "antd";
import React from "react";

class Store {
    @observable isFetching = false;

    @observable columns = [];
    @observable data = [];

    fetchRecords = (page,EditableContext) => {
        this.isFetching = true;
        simpleIndex({page:page}).then(response => {
            let columns = response.data.column;
            columns.push({
                title: '操作',
                dataIndex: 'operation',
                render: (text, record) => {
                    const { editingKey } = this.state;
                    const editable = this.isEditing(record);
                    return editable ? (
                        <span>
              <EditableContext.Consumer>
                {form => (
                    <a
                        onClick={() => this.save(form, record.key)}
                        style={{ marginRight: 8 }}
                    >
                        保存
                    </a>
                )}
              </EditableContext.Consumer>
              <Popconfirm title="Sure to cancel?" onConfirm={() => this.cancel(record.key)}>
                <a>取消</a>
              </Popconfirm>
            </span>
                    ) : (
                        <a disabled={editingKey !== ''} onClick={() => this.edit(record.key)}>
                            编辑
                        </a>
                    );
                },
            });
            this.columns = columns;
            this.data = response.data.data;

        }).finally(() => {this.isFetching = false;});
    };


}

export default new Store()
